/*
 * @Description:  欢迎页封装组件
 * @Author: chenwei
 * @Date: 2019-05-21 14:53:33
 * @LastEditors: chenwei
 * @LastEditTime: 2019-05-22 10:45:41
 */

import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    Alert,
    Image,
    Button,
    Dimensions,
} from 'react-native';

import { deviceInfo } from './common/tool/util';
import AppIntroSlider from 'react-native-app-intro-slider';



const styles = StyleSheet.create({
    mainContent: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'space-around',
        backgroundColor: '#febe29',
    },
    title: {
        fontSize: 22,
        color: 'white',
        backgroundColor: 'transparent',
        textAlign: 'center',
        marginBottom: 16,
    },
    image: {
        width: deviceInfo.deviceWid,
        height: deviceInfo.deviceHei
    }

});

export default class showIntro extends Component {

    constructor(props) {
        super(props);
        this.state = {
            showRealApp: false
        }

        this.introList = this.props.introList;
    }
    _onDone = () => {
        // User finished the introduction. Show real app through
        // navigation or simply by controlling state
        this.props.onClick();

        this.setState({ showRealApp: true });
    }
    _renderItem = (item) => {
        return (
            <View style={styles.mainContent}>
                <Image style={styles.image} source={{ uri: item.img }} />
            </View>
        );
    }


    render() {
        console.log(this.introList, "goto appIntro render .....")
        const pageArray = [];
        for (let i = 0, j = this.introList.length; i < j; i++) {
            let _this = this;
            console.log(_this.introList[i].path)
            pageArray.push({
                key: _this.introList[i].id,
                title: _this.introList[i].title,
                text: 'Description ' + (i + 1),
                img: _this.introList[i].path,
                backgroundColor: '#fa931d'
            });
        }
        return (
            <AppIntroSlider renderItem={this._renderItem} showPrevButton
                skipLabel="跳过"
                prevLabel="后退"
                showSkipButton={true}
                onSkip={this._onDone}

                slides={pageArray} onDone={this._onDone} />
        );
    }
}